package com.lkd.service.Impl;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lkd.entity.Classify;
import com.lkd.mapper.ClassifyMapper;
import com.lkd.service.ClassifyService;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lkd.vo.PageBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 商品类别表 服务实现类
 * </p>
 *
 * @author author
 * @since 2024-08-19
 */
@Service
public class ClassifyServiceImpl extends ServiceImpl<ClassifyMapper, Classify> implements ClassifyService {


    @Autowired
    private ClassifyMapper classifyMapper;

    //添加分类
    @Override
    public boolean addClassify (Classify classify) {
        classify.setClassName (classify.getClassName ());
        return save (classify);
    }

    //获取分类基本信息
    @Override
    public PageBean<Classify> searchByPage (
            Integer pageIndex, Integer pageSize, String className) {
        Page page = new Page (pageIndex,pageSize);
        LambdaQueryWrapper<Classify> wrapper = new LambdaQueryWrapper ();
        wrapper.eq (StrUtil.isNotEmpty (className),Classify::getClassName,className);
        page=getBaseMapper ().selectPage (page,wrapper);

        return new PageBean<> (page);
    }
    //获取分类基本信息
    @Override
    public Classify getBaseMsg (String classId) {
        Classify classify = classifyMapper.selectById (classId);
        return classify;
    }




}
